//页面或组件中用到的动态参数，比如设备管理->终端管理-> 点击左侧单位，右侧列表需要根据左侧选择的单位代码进一步请求数据， 该store使用sessionStorage存储
import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useDynamicParamsStore = defineStore(
  'dynamicParams',
  () => {
    const dynamicParams = ref({})
    const setDynamicParams = (key, value) => {
      // dynamicParams.value = Object.assign(dynamicParams.value, value)
      dynamicParams.value[key] = value
    }
    const delDynamicParams = (key) => {
      // dynamicParams.value = Object.assign(dynamicParams.value, value)
      delete dynamicParams.value[key]
    }

    return {
      dynamicParams,
      setDynamicParams,
      delDynamicParams
    }
  },
  {
    persist: true,
    storage: sessionStorage
  }
)
